package com.cwj.mansysback.servlet.impl;

import com.cwj.mansysback.entity.LocalAccount;
import com.cwj.mansysback.service.api.ElectiveService;
import com.cwj.mansysback.service.impl.ElectiveServiceImpl;
import com.cwj.mansysback.servlet.util.MyUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class UpdateEleServlet extends HttpServlet {

    ElectiveService eleSer = new ElectiveServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        Statement statement = new Statement(8);

        String cid = req.getParameter("cid");
        String sid = req.getParameter("sid");

        if(cid == null || sid == null){
            MyUtils.writeResponse(resp,statement);
            return;
        }

        if(req.getRequestURI().contains("/Lock/Update/Ele/Score")){

            String cscore = req.getParameter("cscore");
            if(cscore != null){
                if(eleSer.updateEletive(cid,sid,Integer.parseInt(cscore))){
                    statement.setStatue(0);
                }
            }
        }else if(req.getRequestURI().contains("/Lock/Add/Ele")){

            if(eleSer.insertElective(cid,sid,0)){
                statement.setStatue(0);
            }

        }else if(req.getRequestURI().contains("/Lock/Delete/Ele")){
            if(eleSer.deleteElective(cid,sid)){
                statement.setStatue(0);
            }
        }


        MyUtils.writeResponse(resp,statement);


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
